package com.qf.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAdminMapper;
import com.qf.pojo.DtsAdmin;
import com.qf.service.AdminAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;


@Service
public class AdminAdminServiceImpl implements AdminAdminService {

    @Autowired
    private DtsAdminMapper dtsAdminMapper;

    @Override
    public IPage<DtsAdmin> selectList(Integer page, Integer limit, String username, String sort, String order) {

        Page<DtsAdmin> iPage = new Page<>(page, limit);

        QueryWrapper<DtsAdmin> wrapper = new QueryWrapper<>();
        wrapper.like(!StringUtils.isEmpty(username), "username", username);
        wrapper.eq("deleted", false);
        wrapper.orderByAsc("asc".equalsIgnoreCase(order),sort);
        wrapper.orderByDesc("desc".equalsIgnoreCase(order),sort);

        Page<DtsAdmin> dtsAdminPage = dtsAdminMapper.selectPage(iPage, wrapper);

        return dtsAdminPage;
    }

    @Override
    public List<DtsAdmin> selectAll() {

        QueryWrapper<DtsAdmin> wrapper = new QueryWrapper<>();
        wrapper.select("id","username")
                .eq("deleted", false);

        List<DtsAdmin> adminList = dtsAdminMapper.selectList(wrapper);
        return adminList;
    }
}
